package com.misty.common.bean;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    private static Result result;

    public static Result success() {
        result = new Result<>();
        result.setCode(0);
        result.setMsg("成功");
        return result;
    }


    public static Result success(int code) {
        result = new Result<>();
        result.setCode(code);
        result.setMsg("成功");
        return result;
    }

    public static <T> Result success(String msg, T data) {
        result = new Result<>();
        result.setCode(0);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result success(String msg) {
        result = new Result<>();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }

    public static Result success(int code,String msg) {
        result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result<T> success(int code,String msg,T data) {
        result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result error() {
        result = new Result<>();
        result.setCode(-1);
        result.setMsg("失败");
        return result;
    }

    public static Result error(String msg) {
        result = new Result<>();
        result.setCode(-1);
        result.setMsg(msg);
        return result;
    }

    public static Result error(int code) {
        result = new Result<>();
        result.setCode(code);
        result.setMsg("失败");
        return result;
    }

    public static Result error(int code, String msg) {
        result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result<T> error(int code, String msg,T data) {
        result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static boolean isSuccesResult() {
        if(result.code == 0){
            return true;
        }
        return false;
    }

    public static boolean isErrorResult() {
        return !isSuccesResult();
    }
}
